package com.ruoyi.life.service.impl;

import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import cn.hutool.core.util.IdUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.core.utils.SecurityUtils;
import com.ruoyi.life.mapper.SysBillAccountMapper;
import com.ruoyi.life.domain.SysBillAccount;
import com.ruoyi.life.service.ISysBillAccountService;

/**
 * 收款账户Service业务层处理
 *
 * @author yy
 * @date 2021-12-02
 */
@Service
public class SysBillAccountServiceImpl implements ISysBillAccountService {
    @Autowired
    private SysBillAccountMapper sysBillAccountMapper;

    /**
     * 查询收款账户
     *
     * @param id 收款账户ID
     * @return 收款账户
     */
    @Override
    public SysBillAccount selectSysBillAccountById(String id) {
        return sysBillAccountMapper.selectSysBillAccountById(id);
    }

    /**
     * 查询收款账户列表
     *
     * @param sysBillAccount 收款账户
     * @return 收款账户
     */
    @Override
    public List<SysBillAccount> selectSysBillAccountList(SysBillAccount sysBillAccount) {
        return sysBillAccountMapper.selectSysBillAccountList(sysBillAccount);
    }

    /**
     * 新增收款账户
     *
     * @param sysBillAccount 收款账户
     * @return 结果
     */
    @Override
    public int insertSysBillAccount(SysBillAccount sysBillAccount) {
        sysBillAccount.setId(IdUtil.getSnowflake(0, 0).nextIdStr());
        sysBillAccount.setCreateTime(DateUtils.getNowDate());
        sysBillAccount.setCreateBy(SecurityUtils.getUsername());
        List<SysBillAccount> sysBillAccounts=sysBillAccountMapper.selectSysBillAccountListByAcName(sysBillAccount);
        if (sysBillAccounts.size()>0){
            return 0;
        }
        return sysBillAccountMapper.insertSysBillAccount(sysBillAccount);
    }

    /**
     * 修改收款账户
     *
     * @param sysBillAccount 收款账户
     * @return 结果
     */
    @Override
    public int updateSysBillAccount(SysBillAccount sysBillAccount) {
        sysBillAccount.setUpdateTime(DateUtils.getNowDate());
        sysBillAccount.setUpdateBy(SecurityUtils.getUsername());
        List<SysBillAccount> sysBillAccounts=sysBillAccountMapper.selectSysBillAccountListByAcName(sysBillAccount);
        if (sysBillAccounts.size()>0){
            return 0;
        }
        return sysBillAccountMapper.updateSysBillAccount(sysBillAccount);
    }

    /**
     * 批量删除收款账户
     *
     * @param ids 需要删除的收款账户ID
     * @return 结果
     */
    @Override
    public int deleteSysBillAccountByIds(String[] ids) {
        return sysBillAccountMapper.deleteSysBillAccountByIds(ids);
    }

    /**
     * 删除收款账户信息
     *
     * @param id 收款账户ID
     * @return 结果
     */
    @Override
    public int deleteSysBillAccountById(String id) {
        return sysBillAccountMapper.deleteSysBillAccountById(id);
    }
}
